package com.example.myshop.service.Imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.myshop.domain.DistrictDao;
import com.example.myshop.entity.District;
import com.example.myshop.service.DistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DistrictServiceImp extends ServiceImpl<DistrictDao, District> implements DistrictService {
    @Autowired
    DistrictDao districtDao;


    @Override
    public List<District> getByParent(String parent) {
        QueryWrapper<District>queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("parent",parent);
        queryWrapper.orderByAsc("code");
        List<District>list=districtDao.selectList(queryWrapper);
        for(District d:list){
            d.setId(null);
            d.setParent(null);
        }
        return list;
    }

    @Override
    public String getNameByCode(String code) {
        QueryWrapper<District>queryWrapper=new QueryWrapper<>();
        queryWrapper.select("name");
        queryWrapper.eq("code",code);
        District district=districtDao.selectOne(queryWrapper);
        return district.getName();
    }
}
